package com.ims.excel.x02cell;


import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

public class HelloCellWrite {

    public static void main(String[] args) throws Exception{
        Workbook wb = new XSSFWorkbook();


        //创建单元格：sheet -> row -> cell
        Sheet sheet1 = wb.createSheet("第一个Sheet页");
        Row row1 = sheet1.createRow(0);
        Cell cell1 = row1.createCell(0);
        //单元格数据类型：Date
        cell1.setCellValue(new Date());


        //单元格样式CellStyle  CreationHelper，格式化：日期
        CellStyle cellStyle = wb.createCellStyle();
        CreationHelper createHelper = wb.getCreationHelper();
        cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyy-mm-dd hh:mm:ss"));
        cell1.setCellStyle(cellStyle);



        File file = new File("x03-office/x0301-poi/hellExcelV2007.xls");
        OutputStream outputStream = new FileOutputStream(file);
        wb.write(outputStream);
        outputStream.close();
    }

}
